package com.yidu.sanrenxing.login.controller;

import com.yidu.sanrenxing.login.domain.Users;
import com.yidu.sanrenxing.login.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@CrossOrigin
public class UsersController {

    @Autowired
    public UsersServiceImpl usersService;

    /**
     * 登录验证
     * @param username 用户名
     * @param passwordlog 密码
     * @return
     */
    @PostMapping("/select")
    @ResponseBody
    public Users selectByPhone(String username,String passwordlog){
        //封装users对象
        Users users=new Users();
        users.setUphonenum(username);
        users.setUserpwd(passwordlog);
        //判断登录是否成功
        Users users1=usersService.selectByPhonePas(users);
        return users1;
    }

    /**
     * 注册
     * @param users
     * @return
     */
    @PostMapping("/insert")
    @ResponseBody
    public Users insertUsers(Users users){
        //角色编号默认设置为1
        users.setRoleid(1);
        //保存用户的账号信息
        String account = users.getUphonenum();
        Users users1 = null;
        //注册（添加数据库数据）
        if (usersService.insert(users)>0){
            users1 = usersService.selectUserMsgByAccount(account);
        }
        return users1;
    }
}
